﻿using System;
using System.Xml.Serialization;

namespace Kwik.Orm
{
	/// <summary>
	/// Database constraint type
	/// </summary>
	public sealed class Constraint: ISchemaConstraint
	{
		/// <summary>
		/// Create a new Constraint object
		/// </summary>
		public Constraint() { }
		/// <summary>
		/// Create a new constraint object with the supplied name
		/// </summary>
		/// <param name="name">Constraint name</param>
		public Constraint(string name) { this.Name = name; }

		/// <summary>
		/// Constraint name
		/// </summary>
		[XmlAttribute]
		public string Name { get; set; }
		/// <summary>
		/// Constraint type
		/// </summary>
		[XmlAttribute]
		public ConstraintType Type { get; set; }
		/// <summary>
		/// Constraint update action
		/// </summary>
		[XmlAttribute]
		public ConstraintAction UpdateAction { get; set; }
		/// <summary>
		/// Constraint delete action
		/// </summary>
		[XmlAttribute]
		public ConstraintAction DeleteAction { get; set; }
		/// <summary>
		/// Name of the table to which this constraint applies
		/// </summary>
		[XmlAttribute]
		public string Table { get; set; }
		/// <summary>
		/// Name of the column to which this constraint applies
		/// </summary>
		[XmlAttribute]
		public string Column { get; set; }
		/// <summary>
		/// Name of the reference table to which this constraint applies, for foreignkey constraints
		/// </summary>
		[XmlAttribute]
		public string ReferenceTable { get; set; }
		/// <summary>
		/// Name of the reference column to which this constraint applies, for foreignkey constraints
		/// </summary>
		[XmlAttribute]
		public string ReferenceColumn { get; set; }
	}
}
